package com.nbgs.demo.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nbgs.demo.controller.form.ComplainNews;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface ComplainMapper {
    //通过cardNum查询投诉
    @Select("<script>\n" +
            "SELECT\n" +
            "t2.card_num,\n" +
            "t1.complain_type,\n" +
            "t1.complain_tel,\n" +
            "t1.complain_message,\n" +
            "t1.complain_start_date,\n" +
            "t1.complain_end_date,\n" +
            "t1.complain_state\n" +
            "FROM\n" +
            "t_complain as t1\n" +
            "LEFT JOIN\n" +
            "t_card as t2\n" +
            "ON\n" +
            "t1.card_id=t2.card_id\n" +
            "<where>\n" +
            "<if test=\"complainState!=null and complainState!=''\">\n" +
            "AND complain_state=#{complainState}\n" +
            "</if>\n" +
            "</where>\n" +
            "ORDER BY card_num DESC\n" +
            "</script>")
    IPage<ComplainNews> showAll(Page<ComplainNews> page, @Param(value="complainState")String complainState);
  //查询总条数
    @Select("<script>\n" +
            "SELECT\n" +
            "count(t2.card_num)\n" +
            "FROM\n" +
            "t_complain as t1\n" +
            "LEFT JOIN\n" +
            "t_card as t2\n" +
            "ON\n" +
            "t1.card_id=t2.card_id\n" +
            "<where>\n" +
            "<if test=\"complainState!=null and complainState!=''\">\n" +
            "AND complain_state=#{complainState}\n" +
            "</if>\n" +
            "</where>\n" +
            "ORDER BY card_num DESC\n" +
            "</script>")
            int getAll(@Param(value="complainState")String complainState);
   //修改投诉状态
    @Update("<script>\n" +
            "update t_complain \n" +
            "<set>\n" +
            "<if test=\"complainEndDate!=null and complainEndDate!=''\"> \n" +
            "complain_end_date=#{complainEndDate},\n" +
            "</if>\n" +
            "<if test=\"complainState!=null and complainState!=''\">\n" +
            "complain_state=#{complainState}\n" +
            "</if>\n" +
            "</set>\n" +
            "where \n" +
            "card_id=(SELECT card_id from t_card WHERE card_num=#{cardNum})\n" +
            "</script>")
    void updateState(ComplainNews complainNews);
}
